package com.zyd.databindingdemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.zyd.databindingdemo.databinding.ActivityBindOnClickBinding;

    /**
     * 事件绑定事例
     *
     */
    public class BindOnClickActivity extends AppCompatActivity {
        ActivityBindOnClickBinding activityBindOnClickBinding;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            activityBindOnClickBinding= DataBindingUtil.setContentView(this,R.layout.activity_bind_on_click);
            Person person = new Person();
            person.name = "王五";
            person.age = 20;
            activityBindOnClickBinding.setPresenter(new Presenter());
            activityBindOnClickBinding.setPerson(person);

            User user = new User();
            user.name.set("李四");
            user.age.set(22);
            activityBindOnClickBinding.setUser(user);

        }

        public class Presenter{
            public void onClick(View view){
                Log.i("Presenter","onClick");
            }

            public void onClick(Person person){
                Log.i("Presenter",person.name);
                activityBindOnClickBinding.setName(person.name);
            }
        }


    }